using System;

namespace Ausy.Silverlight.Survey.Common.Validation
{
    public class RangeValidator<T> : ValidatorBase<T> where T : IComparable
    {
        public T Min { get; set; }

        public T Max { get; set; }

        public RangeValidator(T min, T max)
        {
            this.DefaultMessage = string.Format("La valeur doit être comprise entre {0} et {1}", Min, Max);

            this.Min = min;
            this.Max = max;
        }

        public override bool Validate(T value)
        {
            return (value.CompareTo(Min) >= 0
                && value.CompareTo(Max) <= 0);
        }
    }
}
